/*constants*/
__DEBUG = true;

__LVL_DEBUG = "log_debugger";
__LVL_ERROR = "log_error";
__LVL_WARN = "log_warn";


var _local_loan_status = {
		1:'待提交'	,
		2:'待审核',
		3:'待考察',
		4:'待审批',
		5:'待复核',
		6:'待放款',
		7:'待回收',
		8:'已结清',
		'-1':'中止',
		'-2':'退回'
};


var cDateFunc = function(dp){
	//var str,p,c = $dp.cal;
	//str = $dp.cal.getP('y')+'-'+$dp.cal.getP('M')+'-'+$dp.cal.getP('d');
	console.info(dp.cal.getNewDateStr());
	$('#interestStartTime').val(dp.cal.getNewDateStr());

	//alert($dp.cal.date);
}

var vcity = top.city;

var checkCard = function(card)  
{  
var message = 'OK';
//是否为空  
if(card === '')  
{  
	message = '请输入身份证号，身份证号不能为空';  
    return false;  
}  
//校验长度，类型  
if(isCardNo(card) === false)  
{  
    message = '您输入的身份证号码不正确，请重新输入';  
    return false;  
}  
//检查省份  
if(checkProvince(card) === false)  
{  
	message ='您输入的身份证号码不正确,请重新输入';  
    return false;  
}  
//校验生日  
if(checkBirthday(card) === false)  
{  
	message ='您输入的身份证号码生日不正确,请重新输入';  
    return false;  
}  
//检验位的检测  
if(checkParity(card) === false)  
{  
	message ='您的身份证校验位不正确,请重新输入';  
    return false;  
}  
return true;  
};  


//检查号码是否符合规范，包括长度，类型  
isCardNo = function(card)  
{  
//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X  
var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;  
if(reg.test(card) === false)  
{  
    return false;  
}  

return true;  
};  

//取身份证前两位,校验省份  
var checkProvince = function(card)  
{  
var province = card.substr(0,2);  
if(vcity[province] == undefined)  
{  
    return false;  
}  
return true;  
};  

//检查生日是否正确  
var checkBirthday = function(card)  
{  
var len = card.length;  
//身份证15位时，次序为省（3位）市（3位）年（2位）月（2位）日（2位）校验位（3位），皆为数字  
if(len == '15')  
{  
    var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;   
    var arr_data = card.match(re_fifteen);  
    var year = arr_data[2];  
    var month = arr_data[3];  
    var day = arr_data[4];  
    var birthday = new Date('19'+year+'/'+month+'/'+day);  
    return verifyBirthday('19'+year,month,day,birthday);  
}  
//身份证18位时，次序为省（3位）市（3位）年（4位）月（2位）日（2位）校验位（4位），校验位末尾可能为X  
if(len == '18')  
{  
    var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;  
    var arr_data = card.match(re_eighteen);  
    var year = arr_data[2];  
    var month = arr_data[3];  
    var day = arr_data[4];  
    var birthday = new Date(year+'/'+month+'/'+day);  
    return verifyBirthday(year,month,day,birthday);  
}  
return false;  
};  

//校验日期  
var verifyBirthday = function(year,month,day,birthday)  
{  
var now = new Date();  
var now_year = now.getFullYear();  
//年月日是否合理  
if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day)  
{  
    //判断年份的范围（3岁到100岁之间)  
    var time = now_year - year;  
    if(time >= 3 && time <= 100)  
    {  
        return true;  
    }  
    return false;  
}  
return false;  
};  

//校验位的检测  
var checkParity = function(card)  
{  
//15位转18位  
card = changeFivteenToEighteen(card);  
var len = card.length;  
if(len == '18')  
{  
    var arrInt = top.factor, arrCh = top.parity;   
    var cardTemp = 0, i, valnum;   
    for(i = 0; i < 17; i ++)   
    {   
        cardTemp += card.substr(i, 1) * arrInt[i];   
    }   
    valnum = arrCh[cardTemp % 11];   
    if (valnum == card.substr(17, 1))   
    {  
        return true;  
    }  
    return false;  
}  
return false;  
};  

//15位转18位身份证号  
var changeFivteenToEighteen = function(card)  
{  
if(card.length == '15')  
{  
    var arrInt = top.factor, arrCh = top.parity, cardTemp = 0, i;     
    card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);  
    for(i = 0; i < 17; i ++)   
    {   
        cardTemp += card.substr(i, 1) * arrInt[i];   
    }   
    card += arrCh[cardTemp % 11];   
    return card;  
}  
return card;  
}; 

var IdentityCodeValid =function(code) { 
    var tip = "";
    var pass= true;
    
    if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
        tip = "身份证号格式错误";
        pass = false;
    }
    
   else if(!top.city[code.substr(0,2)]){
        tip = "地址编码错误";
        pass = false;
    }
    else{
        //18位身份证需要验证最后一位校验位
        if(code.length == 18){
            code = code.split('');
            //∑(ai×Wi)(mod 11)
           
            var sum = 0;
            var ai = 0;
            var wi = 0;
            for (var i = 0; i < 17; i++)
            {
                ai = code[i];
                wi = top.factor[i];
                sum += ai * wi;
            }
            var last = top.parity[sum % 11];
            if(top.parity[sum % 11] != code[17]){
                tip = "校验位错误";
                pass =false;
            }
        }
    }
    //if(!pass) alert(tip);
    return pass;
}

var _local_loan_progress_status = {
		0:'正常',
		1:'回退',
		2:'中止'
};

//获取数据源
var SYS_BASE_DATA = parent.SYS_BASE_DATA;

//生成默认的href
var _set_default_href = parent._set_default_href;



//设置回调函数
var _set_callback ;
var _set_super_callback;
var del_url;
var _set_select_elements = new Array;
if(!console || !console.log || !console.debug || !console.warn || !console.error || !console.trace){
	console = {
			log : function(){},
			debug : function(){},
			warn : function(){},
			error : function(){},
			trace : function(){}
	};
}

var initQuery = function(url){

};

(function(){
	Date.prototype.format = function (mask) { 
		var d = this;

		var zeroize = function (value, length) {

			if (!length) length = 2;

			value = String(value);

			for (var i = 0, zeros = ''; i < (length - value.length); i++) {

				zeros += '0';

			}

			return zeros + value;

		};

		return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0) {

			switch ($0) {

			case 'd':
				return d.getDate();

			case 'dd':
				return zeroize(d.getDate());

			case 'ddd':
				return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];

			case 'dddd':
				return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];

			case 'M':
				return d.getMonth() + 1;

			case 'MM':
				return zeroize(d.getMonth() + 1);

			case 'MMM':
				return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];

			case 'MMMM':
				return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];

			case 'yy':
				return String(d.getFullYear()).substr(2);

			case 'yyyy':
				return d.getFullYear();

			case 'h':
				return d.getHours() % 12 || 12;

			case 'hh':
				return zeroize(d.getHours() % 12 || 12);

			case 'H':
				return d.getHours();

			case 'HH':
				return zeroize(d.getHours());

			case 'm':
				return d.getMinutes();

			case 'mm':
				return zeroize(d.getMinutes());

			case 's':
				return d.getSeconds();

			case 'ss':
				return zeroize(d.getSeconds());

			case 'l':
				return zeroize(d.getMilliseconds(), 3);

			case 'L':
				var m = d.getMilliseconds();

				if (m > 99) m = Math.round(m / 10);

				return zeroize(m);

			case 'tt':
				return d.getHours() < 12 ? 'am' : 'pm';

			case 'TT':
				return d.getHours() < 12 ? 'AM' : 'PM';

			case 'Z':
				return d.toUTCString().match(/[A-Z]+$/);

				// Return quoted strings with the surrounding quotes removed      

			default:
				return $0.substr(1, $0.length - 2);

			}

		});

	};
	$.fn.extend({
		'mSelect':function(config){
			var data,THE_SYS_BASE_DATA = SYS_BASE_DATA;
			if(typeof(config.source)!='undefined' && config.source=='server'){
				//来自服务器数据 需要加上showColumn 表示显示列
				var url = '/sys/SysBasedata/list';
				if(typeof(config.url)!='undefined'){
					url = config.url;
				}
				var requestData = {};
				if(typeof(config.requestData)!='undefined'){
					requestData = config.requestData;
				}
				$.ajax({
					url:url,
					data:requestData,
					type:'post',
					dataType:'json',
					async:false,
					success:function(result){
						if(typeof(result)!='undefined' && result.state == 200){
							var aaData = null;
							if(typeof(requestData.comp)!='undefined' && requestData.comp == 1){
								aaData = result['rows']; 
							}else{
								var datagrid = result.datagrid;
								if(typeof(datagrid)!='indefined'){
									aaData = datagird['aaData'];
								}
							}
							//	if(typeof(datagrid)!='indefined'){
							//var aaData = datagird['aaData'];
							var fieldName = 'text',fieldValue='value';
							if(typeof(config.showColumn)!='undefined'){
								fieldName = config.showColumn['text'];
								fieldValue = config.showColumn['value'];
							}

							if(typeof(aaData)!='undefined' && aaData.length>0){
								var tmpObject =new Object();
								for(var i=0,len =aaData.length;i<len;i++){
									var row = aaData[i];
									var text = row[fieldName];
									var value = row[fieldValue];
									if(typeof(value)!='undefined'){
										tmpObject[value] = text;
									}
								}
								THE_SYS_BASE_DATA = new Object();
								THE_SYS_BASE_DATA[config.baseCode] = tmpObject;
							}

						}
					},
					complete:function(){
					}
				});
			}

			if(typeof(config.baseCode)!='undefined' && typeof(THE_SYS_BASE_DATA[config.baseCode])!='undefined'){
				data = THE_SYS_BASE_DATA[config.baseCode];
			}

			if(typeof(data) == 'undefined' && typeof(config.data)=='undefined'){
				data = {};
			}

			if(typeof(data) == 'undefined' && typeof(config.data)!='undefined'){
				data = config.data;
			}

			var opts = '';
			if(typeof(config.isAllSelect)=='undefined' || config.isAllSelect == true){
				opts = opts + createOpt('','请选择');
			}
			for(var key in data){
				var opt = createOpt(key,data[key]);
				opts = opts + opt;
			}

			function createOpt(key,value){
				return ('<option value="'+key+'">' + value + '</option>');
			}
			
			$(this).empty();
			$(this).append($(opts));

			if(typeof(config.dataOptions)!='undefined'){
				$(this).attr('data-options',config.dataOptions);
			}

			if(typeof(config.myClass)!='undefined'){
				$(this).attr('class',config.myClass);
			}

			if(typeof(width) !='undefined'){
				$(this).css('width',width);
			}

			_set_select_elements.push(this);
			//回调选择框函数
			var callback = config.onchageCallback;
			if(typeof(callback)!='undefined' && typeof(callback) == 'function'){
				$(this).change( function(){
					var value = this.options[this.selectedIndex].value;
					var text = this.options[this.selectedIndex].text;
					callback(text,value);
				});
			}
			
			 
		}
	
	   
	});
	
	

}).call(this);

var console_log = function(msg , level){
	var log_item = $("<li/>");
	log_item.addClass(level);
	//[2015-01-12 14:14:12] [Thread-1012] DEBUG
	var msg_prefix = new Date().format("yyyy-MM-dd HH:ss:mm");
	var level_str = "";
	switch (level) {
	case __LVL_DEBUG:
		level_str ="DEBUG";
		break;
	case __LVL_WARN:
		level_str ="WARN";
		break;
	case __LVL_ERROR:
		level_str ="ERROR";
		break;
	default:
		break;
	}
	log_item.text("[" + msg_prefix + "]"+ "[" + level_str +  "]"+ "\t" + msg);
	$("#console").append(log_item);
};

//加入对默认下拉框显示处理
var _set_select_selected = function(data){
	for(var key in _set_select_elements){
		var one = _set_select_elements[key], name = $(one).attr('name'),value = data[name];
		if(typeof(value)!='undefined'){
			$(one).find('option[value="'+value+'"]').attr("selected",true); 
			$(one).parent().find(".uew-select-text").text($(one).find(":selected").text());
		}
	}
};

//设置lable标签 text
var _set_default_lable_text = function(url,clear,data){
	if(_is_empty(data)){
		_set_lable_text('li span','name',url,clear);
	}else{
		_set_lable_text('li span','name',url,clear,data);
	}

};

////设置lable标签 text
//var _set_default_lable_text = function(config){
//if(_is_empty(data)){
//_set_lable_text('li span','name',url,clear);
//}else{
//_set_lable_text('li span','name',url,clear,data);
//}

//};

//设置lable标签 text
var _set_lable_text = function(tag,attrName,url,clear,data,cellCallback){
	if(_is_empty(data)){
		$.ajax({
			url:url,
			data:{},
			type:'post',
			dataType:'json',
			async:false,
			success:function(result){
				if(typeof(result)!='undefined'){
					data = result;
				}
			},
			complete:function(){
			}
		});
	}

	if(typeof(data) == 'undefined'){
		data = {};
	}
	var arr = $(tag);
	//便利 修改
	$.each(arr,function(index,one){
		var attr = $(one).attr(attrName);//得到name标签值
		//如果需要清掉原来的值
		if(clear){
			$(one).text('');
		}
		if(_is_not_empty(attr)){
			var name,value,index=attr.indexOf('@'),length=attr.length ;
			if(index>0 && index!=(length-1)){
				//包含@ 且不为 xx@格式
				name = attr.substring(0,index);
				//转化数据
				var selectCode = attr.substring(index+1);
				if(selectCode.indexOf('[') == 0 && selectCode.indexOf(']') == selectCode.length-1 ){
					//包含 [ ]
					var format = selectCode.replace('[','').replace(']','');
					var dataStr = data[name];
					if(_is_empty(dataStr)){
						value = '';
					}else{
						value = new Date(dataStr).format(format);
					}
				}else{
					value = top.SYS_BASE_DATA[selectCode][data[name]];
				}
			}else{
				name = attr;
				value = data[name];
			}
			if(typeof(value)!='undefined'){
				$(one).text(value);  
				if(typeof(cellCallback)!='undefined'){
					cellCallback(value,name);
				}
			}
		}
	});
	/*值
	for(var key in arr){
		 var one = arr[key], name = $(one).attr(attrName), value = data[name];
		 if(typeof(value)!='undefined'){
			  $(one).text(value);  
			}
		}*/
};

var down_load = function(id){
	_down_file(id);
};
//下载附件
var _down_file = function(id,url){
	if(_is_empty(id)){
		alert('下载的ID为空!');
		return false;
	}
	var my_url = url;
	if(typeof(url) == 'undefined'){
		my_url = 'sys/SysAccessoryExt/packageAccessory';
	}
	window.location.href = my_url+'?id='+id;
//	$.ajax({
//		url:my_url,
//		data:{'id':id},
//		type:'post',
//		dataType:'json',
//		async:false,
//		success:function(result){
//			if(typeof(result)=='undefined'){
//				alert('获取下载地址异常!');
//				return false;
//			}
//			if(result.state !=200){
//				alert(result.message);
//				return false;
//			}
//			var downUrl = result.data;
//			location.href = downUrl;
//		},
//		complete:function(){
//		}
//	});
};
//var selectCheckAll = function(obj){  
//if($(obj).attr("checked")) {  
//$(obj).attr("checked", false); 
//$(":checkbox").attr("checked", false); 
//} else {  
//$(obj).attr("checked", true);  
//$(":checkbox").attr("checked", true);  
//}

//$('#checkBoxList').val(_get_all_select_value());
//};
//var setChildSelect = function(obj){
//if($(obj).attr("checked")) {  
//$(obj).attr("checked", false); 
//} else {  
//$(obj).attr("checked", true);  
//}
//if (!$("#_sub_child_check").checked) {  
//$("#_select_all").attr("checked", false);  
//}  
//var chsub = $("input[type='checkbox'][id='_sub_child_check']").length; //获取subcheck的个数  
//var checkedsub = $("input[type='checkbox'][id='_sub_child_check']:checked").length; //获取选中的subcheck的个数  
//if (checkedsub == chsub) {  
//$("#_select_all").attr("checked", true);  
//} 
//$('#checkBoxList').val(_get_all_select_value());
//};




var _set_dailog = function(conf,callback){
	if(conf.tip_title){
		$('#_common_tip').find('div.tiptop').find('span').text(conf.tip_title);
	}
	if(conf.tip_img){
		$('#_common_tip').find('div.tipinfo').find('span').find('img').attr('src',parent.basePath + parent._image_suffix + conf.tip_img);
	}
	if(conf.tip_content){
		$('#_common_tip').find('div.tipinfo').find('div.tipright').find('p').text(conf.tip_content);
	}
	_set_callback = callback;
};

var _deal_result_dailog = function(conf,callback){
	if(conf.tip_title){
		$('#_deal_result_tip').find('div.tiptop').find('span').text(conf.tip_title);
	}
	if(conf.tip_img){
		$('#_deal_result_tip').find('div.tipinfo').find('span').find('img').attr('src',parent.basePath + parent._image_suffix + conf.tip_img);
	}
	if(conf.tip_content){
		$('#_deal_result_tip').find('div.tipinfo').find('div.tipright').find('p').text(conf.tip_content);
	}
	_set_callback = callback;
};

var _set_close = function(){
	$("#_common_tip").fadeOut(100);
	if(_set_super_callback && typeof _set_super_callback == 'function'){
		_set_super_callback();
		_set_super_callback = null;
		return false;
	}
	if(_set_callback && typeof _set_callback == 'function'){
		_set_callback();
		_set_callback = null;
	}
};

var _set_result_close = function(){
	$("#_deal_result_tip").fadeOut(100);
	if(_set_super_callback && typeof _set_super_callback == 'function'){
		_set_super_callback();
		_set_super_callback = null;
		return false;
	}
	if(_set_callback && typeof _set_callback == 'function'){
		_set_callback();
		_set_callback = null;
	}
};

var _set_cancel = function(){
	$("#_common_tip").fadeOut(100);
	if(_set_super_callback && typeof _set_super_callback == 'function'){
		_set_super_callback();
		_set_super_callback = null;
		return false;
	}
};

var _set_open = function(){
	$("#_common_tip").fadeIn(200);
};

var _set_result_open = function(){
	$("#_deal_result_tip").fadeIn(200);
};


var _del_data = function(url,data,callback,message){
	$.ajax({
		url:url,
		data:data,
		type:'post',
		dataType:'json',
		success:function(result){
			var tip_content ;
			if(result.state=="200"){
				if(typeof(message) == 'undefined' || typeof(message.success) == 'undefined'){
					tip_content = '删除成功!';
				}else{
					tip_content = message.success;
				}
				_deal_result_dailog({'tip_title':'操作结果','tip_content':tip_content},callback);
				_set_super_callback = callback;
				_set_result_open();
			}else{
				if(typeof(message) == 'undefined' || typeof(message.fail) == 'undefined'){
					tip_content = '删除失败!';
				}else{
					tip_content = message.fail;
				}
				_deal_result_dailog({'tip_title':'操作结果','tip_content':tip_content});
				_set_result_open();
			}
		},
		complete:function(){
		}
	});
};


var _log = function(message){
	if(console && __DEBUG){
		console.log(message);
	}
};




var _get_file_suffix = function(filename){
	var lastIndexOf = filename.lastIndexOf(".");
	var _suffix = filename.substr(lastIndexOf,filename.length);
	return _suffix;
}

var _get_file_name = function(filename){
	var lastIndexOf = filename.lastIndexOf(".");
	var _filename = filename.substr(0,lastIndexOf);
	return _filename;
}

var _validate_form = function(parent){
	var flag = true;
	$(parent + " .uwb-validate-box").each(function(){
		var _flag = $(this).uwb_validate("validate",{
			success : function(){

			},
			fail : function(){
				flag = false;
			}});
	});

	return flag;
}

//_set_form .editpr_lines data
var _set_form = function(parent , data){
	$(parent).find(".uwb-form-element").each(function(){
		var thiz = $(this);
		var name = thiz.attr("name");
		if(!name){
			return true;
		}
		var value = data[name];
		thiz.val(value);
	});
};

var _alert =  function(msg,title,flag) {
	if(flag){
		$.messager.alert(title || "Tips" , msg || "N/A", flag);
	}else{
		$.messager.alert(title || "Tips" , msg || "N/A");
	}
}

var _get_upload_params =  function() {
	var params = {
			"uploadUserId": "",   //����ط��ƿ�
			"paramKey":"system_params",   //�̶�ֵ
			"uploadPathKey":"upload_path",  //�̶�ֵ
			"displayPathKey":"upload_url_prefix",  //�̶�ֵ
			"extraPath":"/appIcon",   //�̶�ֵ
			"scale" : true,  //�̶�ֵ
			"scaleWidth":90, //�̶�ֵ
			"scaleHeight":90 //�̶�ֵ
	}

	return params;
}

var _is_not_empty = function(value){
	return !_is_empty(value);
}

var _is_empty = function(_value){
	_value = $.trim(_value);
	if("" != _value && "null" != _value && "undefined" != _value){
		return false;
	}
	return true;
}

var _is_array = function(obj){
	return Object.prototype.toString.call(obj) == '[object Array]';
}

var _def_value = function(value,def_value){
	var _value = $.trim(value);
	if("" != _value && "null" != _value && "undefined" != _value){
		return value;
	}
	return def_value;
}

/**
 * <tr class="odd">
 */
var _renderTemplate = function (template,data,def) {
	with(data) {
		return template.replace(/\:\:\{([_\.a-zA-Z0-9]+)\}/g,function(t,c) {
			var res = null;
			try{
				res = eval("("+c+")");
			}catch(e){
				res = def || "N/A";
			}
			return res;
		});
	}
};

var _toFixedDecimal = function(x,n) {
	var f = parseFloat(x);
	if (isNaN(f)) {
		return null;
	}

	var f = Math.round(x*100)/100;
	var s = f.toString();
	var rs = s.indexOf('.');
	if (rs < 0) {
		rs = s.length;
		s += '.';
	}

	while (s.length <= rs + n) {
		s += '0';
	}
	return s;
};

var appPath =  '';
/**
 * �ж����ڸ�ʽyyyy-MM-dd
 * @param {} dateString
 * @return {Boolean}
 */
function _isDate(dateString)   {
	if(typeof(dateString) == "undefined" || !jQuery.trim(dateString)){
		return true;
	}
	var reg = /^(\d{4})-(\d{2})-(\d{2})$/;     
	var str = dateString;     
	var arr = reg.exec(str);     
	if (!reg.test(str)){
		return false;
	}
	return true;
} 

/**
 * ��������ʱ���ʽ
 * @param {} dateTimeString
 * @return {Boolean}
 */
function _isDateTime(dateTimeString)   {
	if(typeof(dateTimeString) == "undefined" || !jQuery.trim(dateTimeString)){
		return true;
	}
	var reg = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;     
	var str = dateTimeString;     
	var arr = reg.exec(str);     
	if (!reg.test(str)){
		return false;
	}
	return true;
}

/*
$.fn.serializeObject = function(){    
        var o = {};    
        var a = this.serializeArray();  
        $.each(a, function() {    
            if (o[this.name]) {    
                if (!o[this.name].push) {    
                    o[this.name] = [ o[this.name] ];    
                }    
                o[this.name].push(jQuery.trim(this.value) || '');    
            } else {    
                o[this.name] = jQuery.trim(this.value) || '';    
            }    
        });    
        return o;    
	};
 */

/**
������״̬�������˸��
 */
$(document).keydown(function(){
	if(!_common_key(arguments[0])){
		return false;
	}
});

function _common_key(e){
	var srcType ;
	var isReadOnly = "";
	if(e.srcElement){//IE
		srcType = e.srcElement.type;
		if(e.srcElement.attributes.readOnly){
			var isReadOnly =e.srcElement.attributes.readOnly.value;
		}
	}else if(e.target){//Firefox
		srcType = e.target.type;
	}
	var isShielding = false;
	if(srcType != "text" && srcType != "textarea" && srcType != "password"){
		isShielding = true;		
	}
	if(isReadOnly == "true"){
		isShielding = true;
	}
	if(isShielding){
		var keynum;
		if(window.event){//IE
			keynum = e.keyCode;
		}else if(e.which){// Netscape/Firefox/Opera
			keynum = e.which;
		}
		if(keynum == 8){
			return false;
		}
	}
	return true;
}

function _invoke_ajax(args){
	if(!args){
		return false;
	}

	var error_callback = null;
	if($.isFunction(args.error)){
		error_callback = args.error; 
	}

	args.error = function (XMLHttpRequest, textStatus, errorThrown){
		if(XMLHttpRequest.status == 403){
			window.location = appPath+"/";
		}else if(error_callback){
			error_callback(XMLHttpRequest, textStatus, errorThrown);
		}
	}

	$.ajax(args);

	return true;
}

/**
 * �ڸ����ڴ������ر�ǩ
 * @param {} domId
 */
/*
function createParentHiddenDom(domId){
	var parentWindow;
	if(window.opener){
		parentWindow = window.opener;
	}else{
		parentWindow = window.parent;
	}
	if($(parentWindow.document.body).find("#"+domId).length == 0){
		$(parentWindow.document.body).append("<input type='hidden' id='"+domId+"' />");
	}
}*/

/**
 * �滻ҳ�������ַ����/
 * @param v
 */
function _valueReplace(v){
	v=v.toString().replace(new RegExp('(["\"])', 'g'),"\\\"");
	return v; 
}

/**
 * ��ȡ��ǰʱ���ַ�"yyyy-MM-dd HH:mm:ss"��ʽ
 * @return {}
 */
function _getCurrentTimeString(){
	var date = new Date();
	return  date.getFullYear() + 
	"-" +
	((new String(date.getMonth()+1)).length==1?"0"+(date.getMonth()+1):(date.getMonth()+1)) +
	"-" +
	((new String(date.getDate())).length==1 ? ("0"+date.getDate()) : date.getDate()) +
	" " +
	((new String(date.getHours())).length==1 ? ("0"+date.getHours()) : date.getHours()) +
	":" +
	((new String(date.getMinutes())).length==1 ? ("0"+date.getMinutes()) : date.getMinutes()) +
	":" +
	((new String(date.getSeconds())).length==1 ? ("0"+date.getSeconds()) : date.getSeconds());
}

//查看想贷款详情
var loan_query = function(id,clientId){
	console.info(id+","+clientId);
	parent._do_goto_right(parent.basePath+'jsp/loan/loan_detail.jsp?id='+id+'&clientId='+clientId);
};

//查看贷款进度
var loan_process = function(id){
	$.dialog({
		title:"贷款进度",
		width: 1000,
		height: 500,
		content: 'url:jsp/loan/loan_process.jsp?id='+id
	});
};
